package com.yxy.controller.user;

import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.vo.VisitVO;
import com.yxy.service.VisitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(RequestMapperConstant.USER_REQUEST_MAPPER + "visit")
@Slf4j
public class VisitController {

     @Autowired
     private VisitService visitService;

    /**
     * 添加访问记录
     *      添加时进行时间的判断，若最近的一次访问时间为前一天，则进行添加新的访问量记录
     * @param userId
     * @return
     */
    @PutMapping("/addVisit/{userId}")
    public Result addVisit(@PathVariable int userId){
        log.info("判断访问时间，进行添加记录");
        visitService.add(userId);
        return Result.success("");
    }

    /**
     * 获取访问量信息
     * @return
     */
    @GetMapping("/getVisit")
    public Result<VisitVO> getVisit(){
        log.info("获取访问量信息");
        VisitVO visitVO = visitService.getVisit();
        return Result.success("", visitVO);
    }
}
